extensible effects
モナドの合成手法のひとつ.
既に知っているとよいと思われる知識
モナド
モナド変換子
Free monad
Freer Monad (optional)
モチベーション
DSL を書きたい
モナド変換子のつらみ
意味論の固定
合成順の固定
lift いっぱい書くのつらい
MonadReader r m | m -> r における m -> r という FunctionalDependencies がキツい
同じ種類の副作用は一層までしか積めない
概要
ryota-ka.icon あとでかく
HERP での活用方法の一例
ユースケース層を extensible effects を用いて書いている
code:haskell
-- 雰囲気です (実際のコードじゃないです)
addTalent
:: forall effs
. ( TalentIDGenerator.HasEff effs -- このユースケース内ではこういう effect を使う(使える)よ〜 という表明
, TalentRepository.HasEff effs
, Time.HasEff effs
)
=> TalentAttributes
-> Talent
addTalent attributes = do
id <- TalentIDGenerator.ask -- 実装非依存 (連番かな?UUID かな?ULID かな?)
createdAt <- Time.ask -- 実装非依存 (実行時の時刻かな?決め打ちの値かな?)
let talent = Talent { id, attributes, createdAt }
TalentRepository.store talent
return talent
こんなん HERP の他に production で使ってる会社あるんか?w
GitHub
ソースコードの静的解析ツールである Semantic の実装にあたって fused-effects というライブラリが作られた
Building Haskell Programs with Fused Effects (Strangeloop 2019 での発表動画)
リクルートマーケティングパートナーズ
Scala + CleanArchitecture に Eff を組み込んでみた
アルプ
Scalebase のコードベースは extensible effects を利用して Clean Architecture してるらしい
実装
ryota-ka.icon 誰か書いて!w
Free monad
Open union
type-aligned sequence
Reflection without Remorse
references
Extensible Effects: an alternative to Monad Transformers
Freer Monads, More Extensible Effects